import java.util.ArrayList;
import java.util.List;

public class MathUtil {
	public static int randomNum(int max) {
		return (int) (Math.random() * max);
	}

	private static double money = 0;

	public static void main(String[] args) {
		Shoe s = new Shoe(1);
		List<Object[]> l1 = Cfunction(s.getpList().toArray(), 2);
		int playerWin = 0;
		int playerLoss = 0;
		int tieCount = 0;

		for (Object[] o : l1) {
			System.out.println(l1.size());
				System.out.println("tieCount :          " + (tieCount * 1.0/(playerLoss+playerWin+tieCount)));
				System.out.println("Banker win:          " + (playerLoss * 1.0/(playerLoss+playerWin+tieCount)));
				System.out.println("Banker loss:         " + (playerWin* 1.0/(playerLoss+playerWin+tieCount) ));
	
			
			Shoe s1 = new Shoe(1);
			s1.dealSpeicalCard((P) o[0]);
			s1.dealSpeicalCard((P) o[1]);
			
			P p1 = ((P) o[0]);
			P p2 = ((P) o[1]);
			int firstCount = 10;
			int firstCountDeal = 10;
			int count = 10;
			int countDeal = 10;
			if (p1.getNum() < 10) {
				count = count + p1.getNum();
				firstCount = firstCount + p1.getNum();
			}
			if (p2.getNum() < 10) {
				count = count + p2.getNum();
				firstCount = firstCount + p2.getNum();
			}

			List<Object[]> l2 = Cfunction(s1.getpList().toArray(), 2);

			for (Object[] o1 : l2) {

				Shoe s2 = new Shoe(1);
				s2.dealSpeicalCard(p1);
				s2.dealSpeicalCard(p2);
				s2.dealSpeicalCard((P) o1[0]);
				s2.dealSpeicalCard((P) o1[1]);

				P p4 = ((P) o1[0]);
				P p5 = ((P) o1[1]);
				s2.dealSpeicalCard(p4);
				s2.dealSpeicalCard(p5);


				
				
				if (p4.getNum() < 10) {
					countDeal = countDeal + p4.getNum();
					firstCountDeal = firstCountDeal + p4.getNum();
				}
				if (p5.getNum() < 10) {
					countDeal = countDeal + p5.getNum();
					firstCountDeal = firstCountDeal + p5.getNum();
				}


				
				if ((count % 10 >= 8) || (countDeal % 10 >= 8)) {
					if (count % 10 > countDeal % 10) {
						playerWin++;
					} else if (count % 10 == countDeal % 10) {
						tieCount++;
					} else {
						playerLoss++;
					}


				} else {
					if (count % 10 <= 5) {

						List<Object[]> l3 = Cfunction(s2.getpList().toArray(),
								1);

						for (Object[] o2 : l3) {
							
							Shoe s3 = new Shoe(1);
							s3.dealSpeicalCard(p1);
							s3.dealSpeicalCard(p2);
							s3.dealSpeicalCard(p4);
							s3.dealSpeicalCard(p5);
							

							P p3 = ((P) o2[0]);
							P p6 = null;
							s3.dealSpeicalCard(p3);

							if (p3.getNum() < 10) {

								count = count + p3.getNum();
							}

							if (countDeal % 10 <= 2) {
								List<Object[]> l4 = Cfunction(s3.getpList()
										.toArray(), 1);

								for (Object[] o3 : l4) {

									p6 = ((P) o3[0]);
									s3.dealSpeicalCard((P) o3[0]);
									if (p6 != null && p6.getNum() < 10) {
										countDeal = countDeal + p6.getNum();
									}
									
									if (count % 10 > countDeal % 10) {
										playerWin++;
									} else if (count % 10 == countDeal % 10) {
										tieCount++;
									} else {
										playerLoss++;
									}

								}
							} else if (countDeal % 10 == 3) {
								if (p3.getNum() != 8) {
									List<Object[]> l4 = Cfunction(s3.getpList()
											.toArray(), 1);

									for (Object[] o3 : l4) {

										p6 = ((P) o3[0]);
										s3.dealSpeicalCard((P) o3[0]);

										if (p6 != null && p6.getNum() < 10) {
											countDeal = countDeal + p6.getNum();
										}
										
										if (count % 10 > countDeal % 10) {
											playerWin++;
										} else if (count % 10 == countDeal % 10) {
											tieCount++;
										} else {
											playerLoss++;
										}
									}
								}
							} else if (countDeal % 10 == 4) {
								if (p3.getNum() != 1 && p3.getNum() != 8
										&& p3.getNum() != 9
										&& p3.getNum() != 10
										&& p3.getNum() != 11
										&& p3.getNum() != 12
										&& p3.getNum() != 13) {
									List<Object[]> l4 = Cfunction(s3.getpList()
											.toArray(), 1);

									for (Object[] o3 : l4) {

										p6 = ((P) o3[0]);
										s3.dealSpeicalCard((P) o3[0]);

										if (p6 != null && p6.getNum() < 10) {
											countDeal = countDeal + p6.getNum();
										}
										
										if (count % 10 > countDeal % 10) {
											playerWin++;
										} else if (count % 10 == countDeal % 10) {
											tieCount++;
										} else {
											playerLoss++;
										}
									}
								}
							} else if (countDeal % 10 == 5) {
								if (p3.getNum() == 4 || p3.getNum() == 5
										|| p3.getNum() == 6 || p3.getNum() == 7) {
									List<Object[]> l4 = Cfunction(s3.getpList()
											.toArray(), 1);

									for (Object[] o3 : l4) {

										p6 = ((P) o3[0]);
										s3.dealSpeicalCard((P) o3[0]);

										if (p6 != null && p6.getNum() < 10) {
											countDeal = countDeal + p6.getNum();
										}
										
										if (count % 10 > countDeal % 10) {
											playerWin++;
										} else if (count % 10 == countDeal % 10) {
											tieCount++;
										} else {
											playerLoss++;
										}

									}
								}
							} else if (countDeal % 10 == 6) {
								if (p3.getNum() == 6 || p3.getNum() == 7) {
									List<Object[]> l4 = Cfunction(s3.getpList()
											.toArray(), 1);

									for (Object[] o3 : l4) {

										p6 = ((P) o3[0]);
										s3.dealSpeicalCard((P) o3[0]);

										
										if (p6 != null && p6.getNum() < 10) {
											countDeal = countDeal + p6.getNum();
										}
										
										if (count % 10 > countDeal % 10) {
											playerWin++;
										} else if (count % 10 == countDeal % 10) {
											tieCount++;
										} else {
											playerLoss++;
										}			

									}
								}
							} else if (countDeal % 10 == 7) {

								if (count % 10 > countDeal % 10) {
									playerWin++;
								} else if (count % 10 == countDeal % 10) {
									tieCount++;
								} else {
									playerLoss++;
								}			

							}else{
								if (count % 10 > countDeal % 10) {
									playerWin++;
								} else if (count % 10 == countDeal % 10) {
									tieCount++;
								} else {
									playerLoss++;
								}


							}
							
							


						}

					} else if (count % 10 == 6 || count % 10 == 7) {

						P p6;
						
						
						if (countDeal % 10 <= 5) {
							List<Object[]> l3 = Cfunction(s2.getpList()
									.toArray(), 1);

							for (Object[] o3 : l3) {
								Shoe s3 = new Shoe(1);
								s3.dealSpeicalCard(p1);
								s3.dealSpeicalCard(p2);
								s3.dealSpeicalCard(p4);
								s3.dealSpeicalCard(p5);
								

								p6 = ((P) o3[0]);
								s3.dealSpeicalCard((P) o3[0]);

								if (p6.getNum() < 10) {
									countDeal = countDeal + p6.getNum();
								}
								
								if (count % 10 > countDeal % 10) {
									playerWin++;
								} else if (count % 10 == countDeal % 10) {
									tieCount++;
								} else {
									playerLoss++;
								}


							}

							
						}else{
							if (count % 10 > countDeal % 10) {
								playerWin++;
							} else if (count % 10 == countDeal % 10) {
								tieCount++;
							} else {
								playerLoss++;
							}


						}

					} else {
						if (count % 10 > countDeal % 10) {
							playerWin++;
						} else if (count % 10 == countDeal % 10) {
							tieCount++;
						} else {
							playerLoss++;
						}


					}

				}

			}
			
			
		}

		
		
	}

	public static List<Object[]> Cfunction(Object[] a, int m) {
		int n = a.length;

		List result = new ArrayList();

		int[] bs = new int[n];
		for (int i = 0; i < n; i++) {
			bs[i] = 0;
		}
		// 锟斤拷始锟斤拷
		for (int i = 0; i < m; i++) {
			bs[i] = 1;
		}
		boolean flag = true;
		boolean tempFlag = false;
		int pos = 0;
		int sum = 0;
		// 锟斤拷锟斤拷锟揭碉拷锟斤拷一锟斤拷10锟斤拷希锟饺伙拷锟斤拷锟�01锟斤拷同时锟斤拷锟斤拷锟斤拷锟斤拷械锟�1锟狡讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
		do {
			sum = 0;
			pos = 0;
			tempFlag = true;
			result.add(print(bs, a, m));

			for (int i = 0; i < n - 1; i++) {
				if (bs[i] == 1 && bs[i + 1] == 0) {
					bs[i] = 0;
					bs[i + 1] = 1;
					pos = i;
					break;
				}
			}
			// 锟斤拷锟斤拷叩锟�1全锟斤拷锟狡讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

			for (int i = 0; i < pos; i++) {
				if (bs[i] == 1) {
					sum++;
				}
			}
			for (int i = 0; i < pos; i++) {
				if (i < sum) {
					bs[i] = 1;
				} else {
					bs[i] = 0;
				}
			}

			// 锟斤拷锟斤拷欠锟斤拷锟斤拷械锟�1锟斤拷锟狡讹拷锟斤拷锟斤拷锟斤拷锟揭憋拷
			for (int i = n - m; i < n; i++) {
				if (bs[i] == 0) {
					tempFlag = false;
					break;
				}
			}
			if (tempFlag == false) {
				flag = true;
			} else {
				flag = false;
			}

		} while (flag);
		result.add(print(bs, a, m));

		return result;
	}

	private static Object[] print(int[] bs, Object[] a, int m) {
		Object[] result = new Object[m];
		int pos = 0;
		for (int i = 0; i < bs.length; i++) {
			if (bs[i] == 1) {
				result[pos] = a[i];
				pos++;
			}
		}
		return result;
	}
}
